part of 'widget.dart';

class _RootWidgetTranslation {
  static final delegate = _RootWidgetTranslationDelegate();

  static _RootWidgetTranslation of(BuildContext context) {
    return Localizations.of(context, _RootWidgetTranslation);
  }

  late String _languageCode;

  Future<void> load(Locale locale) async {
    _languageCode = locale.languageCode;
  }

  String _resolve(Map<String, String> translations) {
    return translations[_languageCode]!;
  }

  String get settingsMenuItemLabel {
    return _resolve(const {
      'en': 'Settings',
    });
  }

  String get learningContentBackupToFileMenuItemLabel {
    return _resolve(const {
      'en': 'Backup to the file',
    });
  }

  String get learningContentRestorationFromFileMenuItemLabel {
    return _resolve(const {
      'en': 'Restore from the file',
    });
  }

  String get signingOutMenuItemLabel {
    return _resolve(const {
      'en': 'Sign out',
    });
  }
}

class _RootWidgetTranslationDelegate extends LocalizationsDelegate<_RootWidgetTranslation> {
  @override
  bool isSupported(Locale locale) => const ['en'].contains(locale.languageCode);

  @override
  bool shouldReload(LocalizationsDelegate<_RootWidgetTranslation> old) => false;

  @override
  Future<_RootWidgetTranslation> load(Locale locale) async {
    final translation = _RootWidgetTranslation();
    await translation.load(locale);
    return translation;
  }
}
